/**
 * 项目名：	Rumba Plan
 * 
 * 版权所有(C)，上海海鼎信息工程股份有限公司，2006，所有权利保留。
 * 
 * 文件名：	HFieldState.java
 * 模块说明：	状态输入框 | 服务端界面控件
 * 修改历史：
 * 2006-5-26 - lxm - 创建。
 */
package com.hd123.rumba.jsp;

import java.util.HashMap;

import com.hd123.rumba.request.Dictionary;

/**
 * 状态输入框 | 服务端界面控件
 * <p>
 * 
 * 页面模型：<br>
 * <table border=0 cellspacing=3 cellpadding=0>
 * <tr bgcolor=skyblue>
 * <td>界面元素</td>
 * <td>对象属性</td>
 * </tr>
 * <tr>
 * <td><code>&lt;td&gt;</code></td>
 * <td><i>tdLabel</i></td>
 * </tr>
 * <tr bgcolor=aliceblue>
 * <td><code>&nbsp;&nbsp;...</code></td>
 * <td>参见{@link LabelHField LabelHField}</td>
 * </tr>
 * <tr>
 * <td><code>&lt;td&gt;</code></td>
 * <td><i>tdContent</i></td>
 * </tr>
 * <tr bgcolor=aliceblue>
 * <td><code>&nbsp;&nbsp;&lt;select&gt;</code></td>
 * <td><i>select</i></td>
 * </tr>
 * </table>
 * 
 * @author lxm
 * 
 */
public class HFieldState extends HFieldSelect {

  public HFieldState(Dictionary dd, String name, String caption, Object value, HashMap stateMap,
      Object[] params) {
    super(dd, name, caption, value, params);
    this.stateMap = stateMap;
    assignStateOptions();
  }

  public HFieldState(Dictionary dd, String name, String caption, Object value, HashMap stateMap) {
    super(dd, name, caption, value);
    this.stateMap = stateMap;
    assignStateOptions();
  }

  public HFieldState(Dictionary dd, String name, String caption, Object value, Object[] params) {
    super(dd, name, caption, value, params);
  }

  public HFieldState(Dictionary dd, String name, String caption, Object value) {
    super(dd, name, caption, value);
  }

  private HashMap stateMap = new HashMap();

  /** 属性：状态映射表。 */
  /** @deprecated */
  public HashMap getStateMap() {
    return stateMap;
  }

  /** @deprecated */
  public void setStateMap(HashMap stateMap) {
    this.stateMap = stateMap;
  }

  private void assignStateOptions() {
    Object[] keys = this.stateMap.keySet().toArray();
    for (int i = keys.length - 1; i >= 0; i--) { // 确保按照key的升序排列加入
      Integer value = (Integer) keys[i];
      String caption = (String) this.stateMap.get(value);
      this.getOptions().put(value, caption);
    }
  }

  public String toHTML() {
    this.setSelectStyle(HFieldSelect.VALUE_SELECTSTYLE_COMBOBOX);
    return super.toHTML();
  }

}
